package com.haoshuang.zhouzhoubang.ui.page.message.child.team

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.MessageBean
import com.haoshuang.zhouzhoubang.model.bean.TeamMessageBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class TeamMessageViewModel : BaseViewModel() {

    /**
     * 获取门店消息
     */
    val getMessageListData = StatefulMutableLiveData<ResponseBean<MutableList<TeamMessageBean>>>()
    fun getMessageList(p: Int) = netRequest {
        start { getMessageListData.value = StateData.Loading }
        request { ApiRepo.getMessageList(p)  }
        success { getMessageListData.value = StateData.Success(it) }
        error { code, msg ->
            getMessageListData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 设置消息已读
     */
    val masterSetMessageReadData = StatefulMutableLiveData<Int?>()
    fun masterSetMessageRead(id: Int?, type: Int) = netRequest {
        start { masterSetMessageReadData.value = StateData.Loading }
        request { ApiRepo.masterSetMessageRead(id, type)  }
        success { masterSetMessageReadData.value = StateData.Success(id) }
        error { code, msg ->
            masterSetMessageReadData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 门店消息中的申请操作
     */
    val operateTeamData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun operateTeam(message_id: Int?, consent: Int) = netRequest {
        start { operateTeamData.value = StateData.Loading }
        request { ApiRepo.operateTeam(message_id, consent)  }
        success { operateTeamData.value = StateData.Success(it) }
        error { code, msg ->
            operateTeamData.value = StateData.Error(code, msg)
        }
    }
}